import React, { PureComponent } from 'react';

import E from 'wangeditor';
import "./index.less";

class Ueditor extends PureComponent{
    constructor(props){
        super(props);
        this.state = {
            editor:null,
            id:this.props.name?props.name:null
        }
    }
    render(){
        const { id } = this.state
        return (
            <div ref={id} id={id}>
            </div>
        )
    }

    componentDidMount () {
        let { id } = this.state;
        let { content, handleChange } = this.props;
        const editor = new E(this.refs[id]);
        editor.customConfig.zIndex = 100;
        editor.customConfig.pasteFilterStyle = false;
        editor.customConfig.onchange = function (html) {
            // html 即变化之后的内容
            handleChange(html);
        }
        editor.create()
        editor.txt.html(content)
        //console.log(this.refs[id])
    }

}

export default Ueditor;
//<Ueditor name={data['name']} content={data['value']} handleChange={this.editorChange.bind(this,data)} />